﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufWorkerThread.h"
#include "GnufAsynchronousTaskManager.h"
#include "GcmpUiBase.h"

namespace gnuf {
    
    /// \brief AsynchronousThreadTask intends to execute the task in a thread. This 
    /// kind of task is really asynchronous, compared with AsynchronousDeferredTask.
    ///
    /// \see AsynchronousDeferredTask.
    ///
    
    class GCMP_UIBASE_EXPORT AsynchronousThreadTask
        : public AsynchronousTask
        , public WorkerThread
    {
    public:
        AsynchronousThreadTask(
            AsynchronousTask::ESubtype,
            IAsynchronousTaskHandler * pHandler = nullptr);
        virtual ~AsynchronousThreadTask();

        virtual void execute() override final;
        virtual bool isExecuting() const override final;

    protected:
        // Inherits from WorkerThread...
        virtual void onWork() override final;
        virtual void onWorkFinished() override final;

        // Do execute. Return true if finished. Return false if not finished.
        virtual bool onExecute() = 0;

    private:
        bool m_finished;
    };
    
}
